import csv,requests,json,random,sys
url = 'http://localhost/api/sjxg.php'
path='sc.csv'
#try:
#    time=sys.argv[1]
#except:
#    time='2015'
time=2022
rowc=2
while time != 2010:
    try:
        csvreader=csv.reader(open(path,encoding="gbk"))
        data=[]
        for row in csvreader:
            data.append({"time":time,"km":row[1],"value":row[rowc]})
        #data.append({"time":time,"km":row[1],"value":str(random.randint(100,1000))})
        #data.append({"id":row[0],"name":row[1]})
    except:
        csvreader=csv.reader(open(path,encoding="utf-8"))
        data=[]
        for row in csvreader:
            data.append({"time":time,"km":row[1],"value":row[rowc]})
            #data.append({"time":time,"km":row[1],"value":str(random.randint(100,1000))})
    for i in range(len(data)):
        if i:
            #print(data[i])
            response  = requests.post(url, json = data[i])
            print (str(time),response.text)
            #print(len(data))
            #print(row)
    rowc = rowc + 1
    time = time - 1
    
#其实有重复读取报表的小bug，但有鉴于数据很少，就懒得优化了。凑合用吧